
package org.bridgen.lang.semantics.ast;
import java.util.*;


public class ConcreteReefDecl extends ReefDecl implements Cloneable {
    public void flushCache() {
        super.flushCache();
    }
     @SuppressWarnings({"unchecked", "cast"})  public ConcreteReefDecl clone() throws CloneNotSupportedException {
        ConcreteReefDecl node = (ConcreteReefDecl)super.clone();
        node.in$Circle(false);
        node.is$Final(false);
    return node;
    }
     @SuppressWarnings({"unchecked", "cast"})  public ConcreteReefDecl copy() {
      try {
          ConcreteReefDecl node = (ConcreteReefDecl)clone();
          if(children != null) node.children = (ASTNode[])children.clone();
          return node;
      } catch (CloneNotSupportedException e) {
      }
      System.err.println("Error: Could not clone node of type " + getClass().getName() + "!");
      return null;
    }
     @SuppressWarnings({"unchecked", "cast"})  public ConcreteReefDecl fullCopy() {
        ConcreteReefDecl res = (ConcreteReefDecl)copy();
        for(int i = 0; i < getNumChildNoTransform(); i++) {
          ASTNode node = getChildNoTransform(i);
          if(node != null) node = node.fullCopy();
          res.setChild(node, i);
        }
        return res;
    }
    // Declared in PatternAnalysis.jrag at line 28

	
	public void checkPatterns(Collection errorList) {
		MatchPattern pattern = firstPattern();
		if (pattern == null) {
			error(errorList, "Missing pattern for node " + getName());
		} else if (!pattern.startsWithValue()) {
			error(errorList, "Match pattern for node " + getName() +
				" must start with a value");
		}
	}

    // Declared in PrettyPrint.jrag at line 100

    
    public void pp(StringBuffer buf) {
    	buf.append(indent());
    	super.pp(buf);
    	buf.append(" = ");
    	for (int i = 0; i < getNumMatchPattern(); i++) {
    		getMatchPattern(i).pp(buf);
    		if (i != getNumMatchPattern()-1) {
    			buf.append(" ");
    		}
    	}
    	buf.append(";\n");
    }

    // Declared in TypeCodeGen.jrag at line 141

	
	public void generateClassAttributes(String indent, StringBuffer buf) {
		super.generateClassAttributes(indent, buf);
		MatchPattern pattern = firstPattern();
		String regExpTail = regExpTail();
			
		if (pattern.isAltPattern()) {
			AltPattern altPattern = (AltPattern)pattern;
		
			// Start values
			buf.append(indent + "public static final String[] START_VALUE = {\n");
			for (int i = 0; i < altPattern.getNumValuePattern(); i++) {
				buf.append(indent + indent + "\"" + altPattern.getValuePattern(i).value() + "\"");
				if (i < altPattern.getNumValuePattern()-1) {
					buf.append(",");
				}
				buf.append("\n");
			}
			buf.append(indent + "};\n");
		
			// Regular expressions
			buf.append(indent + "public static final String[] MATCH_REG_EXP = {\n");
			for (int i = 0; i < altPattern.getNumValuePattern(); i++) {
				buf.append(indent + indent + "\"" + altPattern.getValuePattern(i).regExp() + regExpTail + "\"");
				if (i < altPattern.getNumValuePattern()-1) {
					buf.append(",");
				}
				buf.append("\n");
			}
			buf.append(indent + "};\n");			
			
		} else {
			buf.append(indent + "public static final String START_VALUE = \"" + pattern.value() + "\";\n");
			buf.append(indent + "public static final String MATCH_REG_EXP = \"" + pattern.regExp() + regExpTail + "\";\n");
		}
		
	}

    // Declared in bridgit.ast at line 3
    // Declared in bridgit.ast line 30

    public ConcreteReefDecl() {
        super();

        setChild(new Opt(), 0);
        setChild(new List(), 1);

    }

    // Declared in bridgit.ast at line 12


    // Declared in bridgit.ast line 30
    public ConcreteReefDecl(String p0, Opt<NodeUse> p1, List<MatchPattern> p2) {
        setName(p0);
        setChild(p1, 0);
        setChild(p2, 1);
    }

    // Declared in bridgit.ast at line 18


  protected int numChildren() {
    return 2;
  }

    // Declared in bridgit.ast at line 21

  public boolean mayHaveRewrite() { return false; }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 20
    public void setName(String value) {
        tokenString_Name = value;
    }

    // Declared in bridgit.ast at line 5

    public String getName() {
        return tokenString_Name != null ? tokenString_Name : "";
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 20
    public void setSuperNodeOpt(Opt<NodeUse> opt) {
        setChild(opt, 0);
    }

    // Declared in bridgit.ast at line 6


    public boolean hasSuperNode() {
        return getSuperNodeOpt().getNumChild() != 0;
    }

    // Declared in bridgit.ast at line 10


     @SuppressWarnings({"unchecked", "cast"})  public NodeUse getSuperNode() {
        return (NodeUse)getSuperNodeOpt().getChild(0);
    }

    // Declared in bridgit.ast at line 14


    public void setSuperNode(NodeUse node) {
        getSuperNodeOpt().setChild(node, 0);
    }

    // Declared in bridgit.ast at line 17

     @SuppressWarnings({"unchecked", "cast"})  public Opt<NodeUse> getSuperNodeOpt() {
        return (Opt<NodeUse>)getChild(0);
    }

    // Declared in bridgit.ast at line 21


     @SuppressWarnings({"unchecked", "cast"})  public Opt<NodeUse> getSuperNodeOptNoTransform() {
        return (Opt<NodeUse>)getChildNoTransform(0);
    }

    // Declared in bridgit.ast at line 2
    // Declared in bridgit.ast line 30
    public void setMatchPatternList(List<MatchPattern> list) {
        setChild(list, 1);
    }

    // Declared in bridgit.ast at line 6


    private int getNumMatchPattern = 0;

    // Declared in bridgit.ast at line 7

    public int getNumMatchPattern() {
        return getMatchPatternList().getNumChild();
    }

    // Declared in bridgit.ast at line 11


     @SuppressWarnings({"unchecked", "cast"})  public MatchPattern getMatchPattern(int i) {
        return (MatchPattern)getMatchPatternList().getChild(i);
    }

    // Declared in bridgit.ast at line 15


    public void addMatchPattern(MatchPattern node) {
        List<MatchPattern> list = getMatchPatternList();
        list.addChild(node);
    }

    // Declared in bridgit.ast at line 20


    public void setMatchPattern(MatchPattern node, int i) {
        List<MatchPattern> list = getMatchPatternList();
        list.setChild(node, i);
    }

    // Declared in bridgit.ast at line 24

    public List<MatchPattern> getMatchPatterns() {
        return getMatchPatternList();
    }

    // Declared in bridgit.ast at line 27

    public List<MatchPattern> getMatchPatternsNoTransform() {
        return getMatchPatternListNoTransform();
    }

    // Declared in bridgit.ast at line 31


     @SuppressWarnings({"unchecked", "cast"})  public List<MatchPattern> getMatchPatternList() {
        return (List<MatchPattern>)getChild(1);
    }

    // Declared in bridgit.ast at line 35


     @SuppressWarnings({"unchecked", "cast"})  public List<MatchPattern> getMatchPatternListNoTransform() {
        return (List<MatchPattern>)getChildNoTransform(1);
    }

    // Declared in PatternAnalysis.jrag at line 42
 @SuppressWarnings({"unchecked", "cast"})     public MatchPattern firstPattern() {
        MatchPattern firstPattern_value = firstPattern_compute();
        return firstPattern_value;
    }

    private MatchPattern firstPattern_compute() {  return (getNumMatchPattern() > 0) ? getMatchPattern(0) : null;  }

    // Declared in PatternAnalysis.jrag at line 46
 @SuppressWarnings({"unchecked", "cast"})     public boolean hasMultipleStartValues() {
        boolean hasMultipleStartValues_value = hasMultipleStartValues_compute();
        return hasMultipleStartValues_value;
    }

    private boolean hasMultipleStartValues_compute() {  return firstPattern() != null && firstPattern().isAltPattern();  }

    // Declared in TypeCodeGen.jrag at line 265
 @SuppressWarnings({"unchecked", "cast"})     public String value() {
        String value_value = value_compute();
        return value_value;
    }

    private String value_compute() {
		StringBuffer buf = new StringBuffer();
		for (int i = 0; i < getNumMatchPattern(); i++) {
			MatchPattern pattern = getMatchPattern(i);
			buf.append(pattern.value());
		}
		return buf.toString();
	}

    // Declared in TypeCodeGen.jrag at line 310
 @SuppressWarnings({"unchecked", "cast"})     public String regExp() {
        String regExp_value = regExp_compute();
        return regExp_value;
    }

    private String regExp_compute() {
		StringBuffer buf = new StringBuffer();
		for (int i = 0; i < getNumMatchPattern(); i++) {
			MatchPattern pattern = getMatchPattern(i);
			buf.append(pattern.regExp());
		}
		return buf.toString();
	}

    // Declared in TypeCodeGen.jrag at line 328
 @SuppressWarnings({"unchecked", "cast"})     public String regExpTail() {
        String regExpTail_value = regExpTail_compute();
        return regExpTail_value;
    }

    private String regExpTail_compute() {
		String tail = "";
		for (int i = 1; i < getNumMatchPattern(); i++) {
			MatchPattern pattern = getMatchPattern(i);
			tail += pattern.regExp();
		}
		return tail;
	}

public ASTNode rewriteTo() {
    return super.rewriteTo();
}

}
